<template>
  <router-link
    tag="div"
    :to="'/explain?name='+list.name+'&description='+list.description+'&tips='+list.tips+'&price='+list.specfoods[0].price+'&satisfy_rate='+list.satisfy_rate+'&img='+list.image_path"
    class="body"
  >
    <img :src="'https://elm.cangdu.org/img/' + this.list.image_path" />
    <div>
      <p class="ti">
        <span>{{list.name}}</span>
      </p>

      <P>{{list.description}}</P>
      <P class="sizeUp">
        <span>{{list.tips}}</span>
      </P>
      <p class="sizeUp">
        <span>好评率:{{list.satisfy_rate}}%</span>
      </p>

      <div class="single">
        <span>￥</span>
        <span>{{list.specfoods[0].price}}</span>
        <span>起</span>
        <div class="add">
          <span :class="flag" @click.stop="rom()">-</span>
          <span>{{num}}</span>
          <span @click.stop="increase()">+</span>
        </div>
      </div>
    </div>
  </router-link>
</template>

<script>
export default {
  components: {},
  props: ['list'],
  data() {
    return {
      num: 0, //商品数量
      reduce: null, //是否显示商品减少按钮
      flag: 'prohibit',
      money: 0,

      shopList: {
        shopID: this.$route.query.id,
        goodsID: this.list.iten_id
      }
    }
  },
  methods: {
    newData() {
      this.num = 0
      this.money = 0
      let shopRecord = JSON.parse(localStorage.getItem(this.$route.query.id))
      //判断,内存中有店铺的记录,并且店铺信息中有这道菜的记录时,把这道菜的数量和金额同步到页面上
      if (shopRecord && shopRecord[this.list.item_id]) {
        this.num = shopRecord[this.list.item_id]['num']
        this.money = shopRecord[this.list.item_id]['money']
      }
      if (this.num != 0) {
        this.flag = null
      } else {
        this.flag = 'prohibit'
      }
    },
    increase() {
      this.flag = null
      this.money += this.list.specfoods[0].price
      this.num++
      this.$emit(
        'addNum',
        this.list.item_id,
        this.num,
        this.money,
        this.list.name
      )
    },
    rom() {
      if (this.num != 0) {
        this.num--
        this.money -= this.list.specfoods[0].price
        this.$emit(
          'romNum',
          this.list.item_id,
          this.num,
          this.money,
          this.list.name
        )
        if (this.num == 0) {
          this.flag = 'prohibit'
        }
      }
    }
  },
  created() {
    this.newData()
    //window.console.log(this.list)
  }
}
</script>
<style  scoped>
.body {
  display: flex;
  background-color: #fff;
  padding: 0.6rem 0.4rem;
  border-bottom: 1px solid #f8f8f8;
  position: relative;
}
img {
  width: 2rem;
  height: 2rem;
  display: block;
  margin-right: 0.5rem;
}
.body > div {
  flex: 1;
}
.ti {
  font-size: 3.5vw;
  color: #333;
  font-weight: bold;
  margin-bottom: 0.3rem;
}
.body > div > p:nth-child(2) {
  font-size: 0.7rem;
  color: #999;
  line-height: 1rem;
}
.sizeUp {
  margin-bottom: 0;
}
.sizeUp > span {
  font-size: 0.6rem;
  color: #333;
}
.sizeUp > span:last-child {
  margin-left: 0.4rem;
}
.single {
  position: relative;
}
.single > span:first-child {
  font-size: 0.7rem;
  color: #ff6662;
}
.single > span:last-child {
  font-size: 0.6rem;
  color: #666;
  margin-left: 0.2rem;
}
.single > span:nth-child(2) {
  font-size: 0.9rem;
  color: #ff6662;
}
.detailed {
  height: 100%;
  overflow-y: scroll;
}
.add {
  position: absolute;
  right: 10px;
  top: 0;
  display: flex;
}
.add > span:last-child,
.add > span:first-child {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  border: none;
  text-align: center;
  font-weight: bold;
  background-color: #26a2ff;
  font-size: 0.7rem;
}
.add > span:nth-child(2) {
  margin: 0 0.5rem;
  font-size: 0.8rem;
  font-weight: bold;
}
.add > div:last-child {
  margin-right: 0;
  margin-left: 0.5rem;
}
.prohibit {
  background-color: #aaa !important;
}
</style>